/** 
 * 2011-10-11 上午11:12:18 
 * UdpMessageClassMap.java 
 * author:sunb 
 */
package com.u6.udp.netty;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author sunbin
 * 
 */
public class UdpMessageActionClassMap {

	public final Map<Short, Class<?>> actionClassMap = new ConcurrentHashMap<Short, Class<?>>();

	private static UdpMessageActionClassMap classMap;

	private UdpMessageActionClassMap() {

	}

	public static UdpMessageActionClassMap getInstance() {
		if (classMap == null) {
			initClassMap();
		}
		return classMap;
	}

	private static synchronized void initClassMap() {
		if (classMap == null) {
			classMap = new UdpMessageActionClassMap();
		}
	}

	public Class<UdpAction> lookupRegisteredReapeater(short messageID) {
		Class clazz = (Class) actionClassMap.get(Short.valueOf(messageID));
		return clazz;
	}

	public void registerRepeater(short messageID, Class claxx) {

		Class clazz = (Class) this.actionClassMap.get(Short.valueOf(messageID));
		if (clazz != null) {
			this.actionClassMap.remove(Integer.valueOf(Short.valueOf(messageID)));
		}

		this.actionClassMap.put(Short.valueOf(messageID), claxx);
	}
}
